package com.ruoyi.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.admin.domain.TPatientFamily;
import com.ruoyi.admin.service.ITPatientFamilyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查询关联家属Controller
 * 
 * @author ruoyi
 * @date 2023-01-10
 */
@RestController
@RequestMapping("/patientsystem/patientAndFamily")
public class TPatientFamilyController extends BaseController
{
    @Autowired
    private ITPatientFamilyService tPatientFamilyService;

    /**
     * 查询查询关联家属列表
     */
    @PreAuthorize("@ss.hasPermi('patientsystem:patientAndFamily:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPatientFamily tPatientFamily)
    {
        startPage();
        List<TPatientFamily> list = tPatientFamilyService.selectTPatientFamilyList(tPatientFamily);
        return getDataTable(list);
    }

    /**
     * 导出查询关联家属列表
     */
    @PreAuthorize("@ss.hasPermi('patientsystem:patientAndFamily:export')")
    @Log(title = "查询关联家属", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPatientFamily tPatientFamily)
    {
        List<TPatientFamily> list = tPatientFamilyService.selectTPatientFamilyList(tPatientFamily);
        ExcelUtil<TPatientFamily> util = new ExcelUtil<TPatientFamily>(TPatientFamily.class);
        util.exportExcel(response, list, "查询关联家属数据");
    }

    /**
     * 获取查询关联家属详细信息
     */
    @PreAuthorize("@ss.hasPermi('patientsystem:patientAndFamily:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPatientFamilyService.selectTPatientFamilyById(id));
    }

    /**
     * 新增查询关联家属
     */
    @PreAuthorize("@ss.hasPermi('patientsystem:patientAndFamily:add')")
    @Log(title = "查询关联家属", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPatientFamily tPatientFamily)
    {
        return toAjax(tPatientFamilyService.insertTPatientFamily(tPatientFamily));
    }

    /**
     * 修改查询关联家属
     */
    @PreAuthorize("@ss.hasPermi('patientsystem:patientAndFamily:edit')")
    @Log(title = "查询关联家属", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPatientFamily tPatientFamily)
    {
        return toAjax(tPatientFamilyService.updateTPatientFamily(tPatientFamily));
    }

    /**
     * 删除查询关联家属
     */
    @PreAuthorize("@ss.hasPermi('patientsystem:patientAndFamily:remove')")
    @Log(title = "查询关联家属", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPatientFamilyService.deleteTPatientFamilyByIds(ids));
    }
}
